package com.xwh.week3;

import java.util.HashMap;
import java.util.Map;

public class Practice6 {//自己再看
    private int getCycleLength(int n) {
        Map<Integer,Integer> map = new HashMap<>();
        int state = 1;//余数
        for (int i = 0; ; i++) {
            if (map.containsKey(state)){
                return i- map.get(state); //注意：差值才是循环节长度
            }

            else {
                map.put(state, i);
                state = state * 10 % n;
                if(state==0)
                    return 0;
            }
        }
    }
    public String run() {
        int bestNumber = 0;
        int bestLength = 0;
        for (int i = 1; i <= 1000; i++) {
            int len = getCycleLength(i);
            if (len > bestLength) {
                bestNumber = i;
                bestLength = len;
            }
        }
        return Integer.toString(bestNumber);
    }
    public static void main(String[] args) {
        System.out.println(new Practice6().run());
    }

}
